home *** CD-ROM | disk | FTP | other *** search
- # Source Generated with Decompyle++
- # File: in.pyo (Python 2.5)
-
- from util import Packable, Storage, to_hex
- import struct
- import oscar.capabilities as capabilities
- from oscar.OscarUtil import tlv
- from logging import getLogger
- log = getLogger('rdv.proxy')
- info = log.info
-
- class ProxyHeader(Packable):
- version = 1098
- fmt = ('length', 'H', 'version', 'H', 'command', 'H', 'null', 'I', 'flags', 'H')
- invars = [
- (lambda o: o.version == ProxyHeader.version)]
- commands = Storage(error = 1, initsend = 2, ack = 3, initreceive = 4, ready = 5)
-
- def initsend(cls, screenname, cookie):
- return make_proxy_init(screenname, cookie)
-
- initsend = classmethod(initsend)
-
- def initreceive(cls, screenname, cookie, port):
- return make_proxy_init(screenname, cookie, port)
-
- initreceive = classmethod(initreceive)
-
- SENDFILE = capabilities.by_name['file_xfer']
- _send_file_tlv = tlv(1, SENDFILE)
-
- def make_proxy_init(sn, cookie, port = None):
- if not isinstance(sn, str):
- raise TypeError('screenname must be a str object')
-
- if isinstance(cookie, long):
- cookie = struct.pack('!Q', cookie)
-
- command = None if port else 'initsend'
- length = len(sn) + 41
- if port is None:
- length -= 2
-
- info(command + ' length: %d', length)
- data = ProxyHeader(length, ProxyHeader.version, ProxyHeader.commands[command], null = 0, flags = 0).pack()
- data += struct.pack('B', len(sn)) + sn
- if port:
- data += struct.pack('!H', port)
-
- fullpacket = data + cookie + _send_file_tlv
- log.info_s('proxy packet assembled (%d bytes): %s', len(fullpacket), to_hex(fullpacket))
- return fullpacket
-
-
- def unpack_proxy_ack(data):
- (ack, data) = ProxyHeader.unpack(data)
- (ack.port, ack.ip) = struct.unpack('!HI', data)
- return ack
-
-
- def unpack_proxy_ready(data):
- (ready, data) = ProxyHeader.unpack(data)
- return ready
-
-